#include "main.h"
#include "card.h"
#include "player.h"
#include "phases.h"
#include "game.h"
#include "util.h"

void Game::init(Player *westPlayer, Player *eastPlayer) {
	srand(time(NULL));
	this->westPlayer = westPlayer;
	this->eastPlayer = eastPlayer;
	turncount = 0;
	terminate = false;
	
	phases.push_back(new DrawPhase());
	phases.push_back(new StandbyPhase());
	phases.push_back(new MainPhase1());
	phases.push_back(new BattlePhase());
	phases.push_back(new MainPhase2());
	phases.push_back(new EndPhase());
}

void Game::runGame() {
	while(!terminate) {
		YuPrint("[GAME] Entering round " + ToString(turncount));
		
		if(turncount % 2 == 0) {
			executeTurn(westPlayer, eastPlayer);
		} else {
			executeTurn(eastPlayer, westPlayer);
		}
		
		turncount++;
	}
}

void Game::executeTurn(Player *turnPlayer, Player *opponent) {
	for(std::vector<Phase*> :: iterator i = phases.begin(); i != phases.end(); i++) {
		(*i)->runPhase();
	}
}